﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using Acceron.University.DBAccess;

namespace GA_SCHED_DESIGNER
{
    /// <summary>
    /// Interaction logic for ProfessorsWindow.xaml
    /// </summary>
    public partial class ProfessorsWindow : Window
    {
        Acceron.University.DBAccess.CRM_University_GADataContext context;

        public ProfessorsWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ProfessorsWindow_Loaded);
        }

        void ProfessorsWindow_Loaded(object sender, RoutedEventArgs e)
        {
            context = new Acceron.University.DBAccess.CRM_University_GADataContext();
            dataGrid1.ItemsSource = context.Professors;
        }

        private void Window_Initialized(object sender, EventArgs e)
        {
            
        }

        private void btnAddNew_Click(object sender, RoutedEventArgs e)
        {
            ProfessorInfoWindow infoWin = new ProfessorInfoWindow();
            infoWin.Prof = new Professor();
            var res = infoWin.ShowDialog();

            if (res == true)
            {
                context.Professors.InsertOnSubmit(infoWin.Prof);
                context.SubmitChanges();
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ProfessorInfoWindow infoWin = new ProfessorInfoWindow();
            
            infoWin.Prof = context.Professors.First(pr => pr.Prof_ID == (int)((Button)sender).Tag);
            var res = infoWin.ShowDialog();

            if (res == true)
            {
                context.SubmitChanges();
            }
        }


    }
}
